package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.util.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tao on 2017/6/22.
 */

public class FansListNewTask extends CouponHttpBaseTask {
    private int mSize;
    private int mPageNo;
    private String mUserId;
    private static final String SEARCHVIDEOJSON = "fansList";

    public FansListNewTask(int size, int pageNo) {
        super(TaskType.MORE_VIDEO_LIST_TASK);
        mSize = size;
        mPageNo = pageNo;
    }
    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        int pageCount = 0;
        int currentPage = 0;
        int nextPage = 0;
        List<EatShowUserInfo> list = new ArrayList<EatShowUserInfo>();
        if (respJson != null) {
            JSONObject jsonString = respJson.getJSONObject(SEARCHVIDEOJSON);
            currentPage = jsonString.getIntValue(ProtocolConst.CURRENT_PAGE);
            pageCount = jsonString.getIntValue(ProtocolConst.PAGE_COUNT);
            nextPage = currentPage >= pageCount ? 0 : (currentPage + 1);
            list = JSON.parseArray(jsonString.getString(ProtocolConst.LIST_TAG), EatShowUserInfo.class);
        }
        notifyTaskCompleted(nextPage, list);
    }
    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.GET_FANS_LIST);
            JSONObject json = new JSONObject();
            json.put("size", mSize);
            json.put("pageNo", mPageNo);
            request.setData(json.toString());
            request.setApiNo(ApiNo.FANSLIST);
            addRequest(request);
        }
    }
}
